#include "stack.h"
#include "calc.h"

void print_s(char *e)
{
	printf("%c",*e);
}

int main(void)
{
	//1. 检查左右括号是否匹配
	int ret = 0;
	char *expression = "1+2*(3-4)-1/2#";
	STACK *stack = stack_create(sizeof(char));
	ret = PrintMatchPairs(stack,expression);
	if(ret == -1)
	{
		printf("左右括号不匹配\n");
		free(stack);
		exit(1);
	}
	stack_destory(&stack);

	//2. 计算后缀表达式
	int len = strlen(expression);
	char *fix_exp = malloc(len + 1);
	fix_exp[len] = '\0';

	STACK *st_fix = stack_create(sizeof(char));
	if (st_fix == NULL)
		exit(1);
	postfix(st_fix, expression, fix_exp);

	//3. 根据后缀表达式计算结果
	STACK *st = stack_create(sizeof(double));
	if (st == NULL)
		exit(1);

	Calculator(st, fix_exp);

	stack_destory(&st);
	stack_destory(&st_fix);

	free(fix_exp);

	return 0;
}